home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 21 / AACD 21.iso / AACD / Graphics / SMan / MorphOS / Source / ULP4mos.asm < prev    next >
Encoding:
Assembly Source File  |  2001-03-09  |  4.7 KB  |  191 lines

  1.  
  2. #    r0        volatile, may be used by function linkage
  3. #    r1        stack pointer
  4. #    r2        table of contents register
  5. #    r3    .. r4    volatile, pass 1st - 2nd int args, return 1st - 2nd ints
  6. #    r5  .. r10    volatile, pass 3rd - 8th int args
  7. #    r11        volatile, pass static chain if language needs it
  8. #    r12        volatile, used by dyn linker, exception handling
  9. #    r13 .. r31    saved
  10.  
  11.  
  12.  
  13. #    f0        volatile
  14. #    f1  .. f4    volatile, pass 1st - 4th float args, return 1st - 4th floats
  15. #    f5  .. f13    volatile, pass 5th - 13th float args
  16. #    f14 .. f31    saved
  17.  
  18. #    Use r23    as CurCnt
  19. #    Use r24    as MaxCnt (Constant value)
  20. #    Use r25    as LPixelBuf
  21. #    Use r26    as location within ColorTable32
  22. #    Use r27    as base address of ColorTable32
  23. #    Use r28    as BPP (that is, bytes per pixel)
  24.  
  25. #    r29    as RightEdge
  26. #    r30    as xtemp (integer)
  27.  
  28.  
  29. #    Note that the following are constants, and independent of xtemp.
  30.  
  31. #    First the integers
  32. #    MaxCnt    in r24
  33. #    LPixelBuf in r25. It changes but need only be loaded 1 time.
  34. #    Base address of ColorTable32 in r27
  35. #    BPP in r28
  36.  
  37. #    Now the floats    (Newly defined)
  38.  
  39. #    3.00 in f14
  40. #    Zr in f15.  It changes as Zr is recalculated.
  41. #    Use f16    as value of yRel.  This is constant for each line.
  42. #    Use f17    Zi.  It's initially yRel, but changes within loop.
  43. #    Use f18    as xRel. Only changes as DX is added for the next pixel.
  44. #    Use f19 as |Z2| Only for comparing with Limit.
  45. #    Use f20    This is scratch and used shortly for 2Zi.
  46. #    Delta x    in f21
  47. #    Two    in f22
  48. #    Limit    in f23
  49. #    Use f24    as Zr2.  This is also a temporary value
  50. #    Use f26 as Zr3.
  51.  
  52.  
  53.     .text
  54.     .sdreg    13
  55.     .global    UseLibP4
  56.     .align    4
  57. UseLibP4:
  58.     mflr    11
  59.     stw    11,4(1)    #Save return address
  60.     stwu    1,-80(1)      #Save stack pointer
  61.     fmr    16,1        #Transfer yrel from f1 to f16
  62.     lis    4,MaxCnt@ha
  63.     lwz    24,MaxCnt@l(4)        #MaxCnt in r24.
  64.     lis    4,LPixelBuf@ha
  65.     lwz    25,LPixelBuf@l(4)    #Get Location of LPixelBuf
  66.     lis    4,ColorTable32@ha
  67.     lwz    27,ColorTable32@l(4)    #Start of color table
  68.  
  69.     lis    4,BPP@ha
  70.     lwz    28,BPP@l(4)             #Number bytes per pixel
  71.     lis    4,Factor@ha
  72.     lfd    25,Factor@l(4)    #Get Factor into f25
  73.     lis    4,Two@ha
  74.     lfd    22,Two@l(4)    #Get Two into f22 as constant
  75.     lis    4,Limit@ha
  76.     lfd    23,Limit@l(4)    #Get Limit into f23 as constant
  77.  
  78.     fadd    14,22,22    #f14 is 4.
  79. #    fadd    14,14,22    #f14 is 6.
  80. #    fdiv    14,14,22    #f14 is 3.
  81.  
  82. #The above could have been done with a global definition of 3.000.
  83.  
  84.     li    30,0        #xtemp = 0.
  85.     fsub    15,22,22    #(float)xtemp = 0.
  86.     lis    4,XCenter@ha
  87.     lfd    10,XCenter@l(4)    #f10 = XCenter
  88.     fsub    15,15,10    #xRel = xRel - XCenter
  89.     fdiv    18,15,25    #xRel = xRel/Factor
  90.  
  91.     lis    4,DX@ha
  92.     lfd    21,DX@l(4)    #Get the real value of Delta x.
  93.     lis    4,RightEdge@ha
  94.     lwz    29,RightEdge@l(4)
  95.  
  96. Start:
  97.     fmr    15,18        #Initial value of Zr is xRel
  98.  
  99. #  The following line was moved before rather than after fmr f17,f16
  100. #  to give the fpu a break.
  101.     li    23,1        #Initialize CurCnt = 1
  102.     fmr    17,16        #yRel into f17 as initial Zi.
  103.     b    l3        #Check to see if to MaxCnt
  104. l2:
  105.     fmul    24,15,15    #Zr2 in f24
  106.     fmul    4,17,17    #Zi2 = Zi*Zi
  107.     fadd    19,24,4    #Zr2 + Zi2 -> f19
  108.     fcmpu    0,19,23    #Compare with Limit in f23.
  109.     ble    0,l6
  110.  
  111. #The following section is not very time-critical as it is only reached once.
  112. #for each pixel
  113.     cmpwi    0,28,2    #See if BPP < 2
  114.     blt    0,l8
  115. l7:
  116.     slwi    10,23,2    #4 times CurCnt for offset in ColorTable32
  117.     add    26,27,10    #Find location of pixel color in ColorTable32
  118.     lwz    11,0(26)    #Get ARGB from ColorTable
  119.     stw    11,0(25)    #Store color in LPixelBuf
  120.     addi    25,25,4    #Point to next location in LPixelBuf
  121.     b    l1
  122. l8:    andi.    3,23,65535    #Prep Color as UWORD for PlotIt
  123.     bl    PlotIt
  124. l9:    b    l1
  125. l6:
  126.     fmul    20,24,14    #Find 4*Zr2
  127.     fsub    27,24,4    #Find Zr2 - Zi2
  128.     fmul    20,20,4    #Now have 4*Zr2*Zi2
  129.  
  130.     fmul    28,27,27    #Square above
  131.     fmul    27,27,14    #4*(Zr2 - Zi2)
  132.     fsub    28,28,20    #Now have (Zr2-Zi2)^2 - 4*Zr2*Zi2
  133.  
  134.     fmul    27,27,17    #4*(Zr2 - Zi2)*Zi
  135.     fmul    17,27,15    #4*(Zr2 - Zi2)*Zi*Zr -> Zi
  136. #    fmr    24,28        #Zr4 -> Zr2
  137.  
  138. #    fadd    15,18,24    #New Zr = xRel + Zr2
  139.     fadd    15,18,28
  140.     addi    23,23,1    #Increment CurCnt
  141.     fadd    17,16,17    #Zi = Zi + yRel
  142.  
  143. l3:
  144.     cmpw    0,23,24    #See if CurCnt < MaxCnt
  145.     blt    0,l2        #Repeat until MaxCnt reached
  146.  
  147.     cmpwi    0,28,2    #See if BPP < 2
  148.     blt    0,l11
  149. l10:
  150.  
  151.     lis    12,4
  152.     addi    12,12,-4
  153.     add    26,27,12    #Find location of pixel color
  154.     lwz    11,0(26)      #Get color
  155.  
  156.     stw    11,0(25)    #Store color in LPixelBuf
  157.     addi    25,25,4    #Point to next pixel in buffer
  158.     b    l1        #Was l12
  159. l11:
  160.     lis    11,1
  161.     addi    3,11,-1    #ffff for PlotIt
  162.     bl    PlotIt
  163. l1:
  164.     fadd    18,18,21    #Find new value of xRel (xRel = xRel + DX).
  165.     addi    30,30,1    #Increment xtemp.
  166.     cmpw    0,30,29    #See if to RightEdge
  167.  
  168.     blt    0,Start    #Repeat until row is done.
  169.     lis    4,LPixelBuf@ha
  170.     stw    25,LPixelBuf@l(4)  #New location in long pixel buffer
  171.     addi    1,1,80        #Balance Stack pointer
  172.     lwz    11,4(1)    #Get return address
  173.     mtlr    11
  174.  
  175.     blr
  176.     .type    UseLibP4,@function
  177.     .size    UseLibP4,$-UseLibP4
  178.  
  179.     .globl    MaxCnt
  180.     .globl    RightEdge
  181.     .globl    XCenter
  182.     .globl    Factor
  183.     .globl    Limit
  184.     .globl    Two
  185.     .globl    LPixelBuf
  186.     .globl    ColorTable32
  187.     .globl    BPP
  188.     .globl    DX
  189.     .globl    PlotIt
  190.  
  191.